/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aiaudio.processing.base.mapreduce;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.WritableComparable;

/**
 *
 * @author nastya
 */
public class CoordinateDoubleValueKey implements WritableComparable<CoordinateDoubleValueKey> {
    private double value;
    private byte[] coordinate;

    public CoordinateDoubleValueKey() {
    }

    public CoordinateDoubleValueKey(double value, byte[] artist) {
        this.value = value;
        this.coordinate = artist;
    }

    public byte[] getCoordinate() {
        return coordinate;
    }

    public double getValue() {
        return value;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        String artistAsString = Bytes.toString(coordinate);
        out.writeUTF(artistAsString);
        out.writeDouble(value);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        String artistAsString = in.readUTF();
        this.coordinate = Bytes.toBytes(artistAsString);
        this.value = in.readDouble();
    }

    @Override
    public int compareTo(CoordinateDoubleValueKey t) {
        if (t == null) {
            return 1;
        }
        String a1 = Bytes.toString(coordinate);
        String a2 = Bytes.toString(t.coordinate);
        return a1.compareTo(a2);
    }
    
}
